var express = require('express');
var router = express.Router();
const amdinApi = require('../api/admins')
const { md5 } = require("../util/salt");

/* GET home page. */
router.get('/login', async function (req, res, next) {
    const { adminName, adminPassword } = req.query;
    let data = await amdinApi.login({ adminName, adminPassword });
    res.send(data)
});
router.post('/reg', async function (req, res, next) {
    const { adminName, adminPassword } = req.query;
    let data = await amdinApi.reg({ adminName, adminPassword });
    res.send(data)
});
router.get('/get', async function (req, res, next) {
    const { page, limit } = req.query;
    let data = await amdinApi.get({ page, limit });
    res.send(data)
});
router.put('/update/:_id', async function (req, res, next) {
    const { _id } = req.params;
    const { adminName, adminPassword } = req.query;
    let data = await amdinApi.update({ _id }, { adminName, adminPassword: md5(adminPassword) });
    res.send(data)
});
router.delete('/del/:_id', async function (req, res, next) {
    const { _id } = req.params;
    let data = await amdinApi.del({ _id });
    res.send(data)
});
router.get('/search', async function (req, res, next) {
    let data = await amdinApi.search(req.query);
    res.send(data)
});

module.exports = router;
